package tr.edu.metu.is550.isell.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import tr.edu.metu.is550.isell.R;

public class MainActivity extends Activity {
    private Button btnConfiguration;
    private Button btnRegisterUser;
    private Button btnLogin;
    private Button btnAddProperty;
    private Button btnSearchProperty;
    private Button btnLogout;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnConfiguration = (Button) findViewById(R.id.btnConfiguration);
        btnRegisterUser = (Button) findViewById(R.id.btnRegisterUser);
        btnLogin = (Button) findViewById(R.id.btnLogin);
        btnAddProperty = (Button) findViewById(R.id.btnAddProperty);
        btnSearchProperty = (Button) findViewById(R.id.btnSearch);
        btnLogout = (Button) findViewById(R.id.btnLogout);

        btnSearchProperty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), SearchPropertyActivity.class);
                startActivity(myIntent);
            }
        });
        btnConfiguration.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), ConfigActivity.class);
                startActivity(myIntent);
            }
        });

        btnRegisterUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), RegisterUserActivity.class);
                startActivity(myIntent);
            }
        });

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
                startActivity(myIntent);
            }
        });

        btnLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = defaultSharedPreferences.edit();
                editor.remove("isLoggedIn");
                editor.remove("userName");
                editor.remove("password");
                editor.apply();
                Toast.makeText(getApplicationContext(), "Logged out!", Toast.LENGTH_SHORT).show();

            }
        });

        btnAddProperty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), AddPropertyActivity.class);
                startActivity(myIntent);
            }
        });

    }

}
